Skip to content

feat: copy proto .d.ts back to source tree#2766

Draft
alexeagle wants to merge 2 commits intomainfrom
diff.bzl.d.ts
Draft

feat: copy proto .d.ts back to source tree#2766
alexeagle wants to merge 2 commits intomainfrom
diff.bzl.d.ts

Conversation

@alexeagle
Copy link
Copy Markdown
Contributor

This is a missing feature compared with the now-deprecated ts_proto_library

Thanks to @kormide for getting the new diff.bzl out the door!

@aspect-workflows

This comment was marked as off-topic.

@github-actions

This comment was marked as outdated.

Comment thread js/private/proto.bzl Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad5473a234

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread examples/proto/foo_pb.d.ts Outdated
@jbedard jbedard requested a review from kormide March 11, 2026 22:40
Comment thread js/proto.bzl Outdated
**kwargs
)

def js_proto_library(name, proto, copy_types = None):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't the proto target have many proto files? Doesn't that mean we need to output many "types" files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but I'm also hoping to avoid making the user repeat the list of output files like we did in rules_ts... working on it

Copy link
Copy Markdown
Member

@kormide kormide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Will let @jbedard approve.

in deps attribute of starlark_doc_extract rule //js:proto.doc_extract: missing bzl_library targets for
Starlark module(s) @diff.bzl//:diff.bzl

Did I mess up the bzl_library targets in diff.bzl?

Comment thread js/private/proto.bzl Outdated
@alexeagle
Copy link
Copy Markdown
Contributor Author

alexeagle commented Mar 11, 2026

@kormide

Did I mess up the bzl_library targets in diff.bzl

no, it's the same pattern as the other *.bzl modules - the syntax sugar is for end users, rules should use the @diff.bzl//diff:defs.bzl load statement for stardocs. Updated here.

Comment thread js/private/proto.bzl
Comment thread js/proto.bzl
gen_file = "_{}.gen_{}.d.ts".format(name, i)
diff_target = "{}.diff_{}".format(name, i)
select_file(name = gen_file, srcs = "_{}.types".format(name), subpath = src_file)
diff(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kormide did you guys think about any APIs to support multiple files?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. Open to suggestions. @alexeagle and I are also discussing async.

Comment thread js/private/proto.bzl

def _js_proto_library_impl(ctx):
return [
OutputGroupInfo(types = ctx.attr.proto[JsInfo].types),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok this has no DefaultInfo(files) with the JsInfo.sources like js_library does?

I think having no DefaultInfo(runfiles) is probably correct though? Or that might be a discussion+test for another day...

@jbedard
Copy link
Copy Markdown
Member

jbedard commented Mar 12, 2026

You can rebase/pull to get my workaround for the bazel 9.0.1 issue (pinning to 9.0.0 for now).

Comment thread js/proto.bzl
def js_proto_library(name, proto, copy_types = []):
"""Wrap a proto_library to invoke the js_proto_toolchain.

Can copy .d.ts type definitions back to the source folder.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will users want to create a js_proto_library() for every proto_library(), so that all .d.ts files get copied back to the source folder? This makes me wonder if js_proto_library() should use an aspect for this, so that you can get all the .d.ts files copied over without needing to replicate the whole proto_library dependency graph.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users probably do want a lang_proto_library for each proto_library, that's already the common practice and it's Gazelle's job to create those targets in the BUILD file.

If we only wanted to have an aspect on a js_library -> proto_library edge, we already have one of those. I could experiment with the DX of doing it without any js_proto_library targets in the BUILD file.

I'll get an example landed first so we can base our PRs from that.

Also fix a bug where `js_library` deps ran the proto aspect, but
js_binary/js_test did not.

/cc @acozzette
@jbedard jbedard marked this pull request as draft April 1, 2026 17:49
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Alex Eagle seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants